#!/usr/bin/python
# -*- coding: cp1250 -*-

import string
import re
import fm_levenshtein as fml
import fm_levenshteindam as fmd
import fm_soundex as fms
import fm_soundex_dmetaphone as fmm
import fm_soundex_nysiis as fmn

def string_prep(a):
    """ """
    a = string.lower(a)
    a = re.sub(',' ,' ', a)
    a = re.sub('[^a-zA-Z0-9 ]' ,'', a)
    a = re.sub('[aeiyou]' ,'', a)
    a = string.join(sorted(string.split(a, ' ')), ' ')
    a = re.sub(' {2,}' ,' ', a)
    a = string.strip(a)
    return a

def __choose_compare_method(a, b):
    return fmd.dld_geek_nz(a, b)
    #return fml.ld_hetland_org(a, b)

def compare_strings(a, b):
    """ """
    res = {}
    res['a'], res['b'] = string_prep(a), string_prep(b)
    res['lddf'] = float(__choose_compare_method(res['a'], res['b']))
    if len(res['a']) > len(res['b']): res['base'] = res['a']
    else: res['base'] = res['b']
    res['perc'] = int(100 - ((res['lddf']/len(res['base'])
                              ) * 100
                             )
                      )
    return res

def pp_levenstein(a, b):
    """ """
    print "Input strings:"
    print a; print b
    res = compare_strings(a, b)
    print "\nAdjusted strings (before comparison):"
    print res['a']; print res['b']
    print "\nLevenshtein distance: %d \nLength of longer string: %d \nMatching percentage: %d \n" % \
           (res['lddf'], len(res['base']), res['perc'])

def pretty_print_soundex(a):
    """ """
    print a

if __name__ == '__main__':
    """ """
    pass